package com.lanou.bookstore.category.web.servlet;

import com.lanou.bookstore.category.dao.CBookDao;
import com.lanou.bookstore.category.domain.CBook;
import com.lanou.bookstore.category.service.CBookService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet(name = "CBookServlet", urlPatterns = "/cbook.do")
public class CBookServlet extends HttpServlet {
    CBookDao cBookDao = new CBookDao();

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf8");
        response.setContentType("text/html;charset=utf8");
        List<CBook> cBooks = cBookDao.findAll();
        request.setAttribute("cBooks", cBooks);
        request.getRequestDispatcher("/jsps/book/list.jsp").forward(request,response);

    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request, response);
    }
}
